Fixes clock_gettime and rt_ktime_boottime_get_ns#10749
Fixes clock_gettime and rt_ktime_boottime_get_ns#10749lygstate wants to merge 1 commit intoRT-Thread:masterfrom
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
🏷️ Tag: components_libcReviewers: @GorrayLi @mysterywolf Changed Files (Click to expand)
🏷️ Tag: kernelReviewers: @GorrayLi @ReviewSun @hamburger-os @lianux-mm @wdfk-prog @xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-11-12 13:18 CST)
📝 Review Instructions
|
0bc44ca to
5839f13
Compare
c448a01 to
264c203
Compare
28b2e48 to
d8c1321
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR fixes overflow issues in clock_gettime and rt_ktime_boottime_get_ns by improving time conversion precision and enabling 64-bit tick counts on 64-bit architectures. The changes replace the previous resolution-based approach with direct frequency-based calculations to ensure more accurate timing operations.
Key changes:
- Introduces precision-preserving multiplication/division functions (
rt_muldiv_u64,rt_muldiv_u32) - Makes
rt_tick_t64-bit on 64-bit architectures to support long-running programs - Replaces resolution-based time calculations with frequency-based conversions throughout the timing subsystem
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/rttypes.c |
Adds new multiplication/division functions for precision-preserving arithmetic |
include/rttypes.h |
Declares the new rt_muldiv_u64 and rt_muldiv_u32 functions |
include/rtdef.h |
Makes RT_TICK_MAX 64-bit on 64-bit architectures |
components/libc/compilers/common/ctime.c |
Updates timer implementations to use frequency-based calculations |
components/drivers/rtc/dev_soft_rtc.c |
Updates RTC resolution calculation |
components/drivers/ktime/src/ |
Refactors timing subsystem to use frequency instead of resolution |
bsp/rockchip/rk3500/driver/hwtimer/ |
Updates hardware timer interface |
Comments suppressed due to low confidence (2)
src/rttypes.c:1
- Corrected spelling of 'loseless' to 'lossless'.
/*
src/rttypes.c:1
- Corrected spelling of 'loseless' to 'lossless'.
/*
d8c1321 to
9c73d71
Compare
|
@Rbb666 ping |
Currently the return value of clock_gettime and rt_ktime_boottime_get_ns are restricted by rt_ktime_cputimer_getres, as the value of rt_ktime_cputimer_getres are not exactly represent the frequency of the clock, directly using rt_ktime_cputimer_getfrq will ensure the return value of rt_ktime_boottime_get_ns be more exact. And also add function rt_muldiv_u64 rt_muldiv_u32 for not losing precision when convert between cputimer and hrtimer and nanoseconds. Because rt_ktime_boottime_get_ns depends on rt_ktime_cputimer_getcnt and rt_ktime_cputimer_getcnt depends rt_tick_get So the rt_tick_t should be 64bit for long running program. Use `#if defined(ARCH_CPU_64BIT)` is for future allow rt_tick_t can be 64bit on 32bit CPU. Tick count should not be restricted to the CPU Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
9c73d71 to
e13dc95
Compare
拉取/合并请求描述:(PR description)
continue work of #9008
Fixes overflow of
clock_gettimert_ktime_boottime_get_nsthoroughlyCurrently the return value of clock_gettime and rt_ktime_boottime_get_ns are restricted by
rt_ktime_cputimer_getres, as the value ofrt_ktime_cputimer_getresare not exactly represent thefrequency of the clock, directly usingrt_ktime_cputimer_getfrqwill ensure the return value of rt_ktime_boottime_get_ns be more exact.And also add function rt_muldiv_u64 rt_muldiv_u32 for not losing precision when convert between
cputimerandhrtimerandnanoseconds.Because
rt_ktime_boottime_get_nsdepends onrt_ktime_cputimer_getcntandrt_ktime_cputimer_getcntdependsrt_tick_getSo the rt_tick_t should be 64bit for long running program.
Use
#if defined(ARCH_CPU_64BIT)is forfuture allow rt_tick_t can be 64bit on 32bit CPU.
Tick count should not be restricted to the CPU
[
为什么提交这份PR (why to submit this PR)
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up